﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;

namespace WebSite.admin.system
{
    public partial class navigator :BaseAdmin
    {

        // Methods
        private void Display(string parentid, string space)
        {
            string str;
            if (parentid.ToString() == "0")
            {
                str = "Select * From DB_Class Where parentid =0 and isnull(shopId,0)=" + base.AdminShopId + " and (classpcs='顶部' or classpcs='底部' or classpcs='顶部和底部') Order By classorder";
            }
            else
            {
                str = "Select * From DB_Class Where parentid =" + parentid + " and isnull(shopId,0)=" + base.AdminShopId + " Order By classorder";
            }
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(str).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    if (row["Amount"].ToString() != "0")
                    {
                        string str4 = this.Label1.Text;
                        this.Label1.Text = str4 + "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td width=5%><input id='Checkbox1' type='checkbox' name='chk' value=" + row["classid"].ToString() + " /></td><td align=left height=22 width=30%>" + space + "<a href='javascript:open_menu(tr_" + row["classid"].ToString() + ");'>";
                        this.Label1.Text = this.Label1.Text + "" + row["classname"].ToString() + "";
                        this.Label1.Text = this.Label1.Text + "</a></td>";
                        if (row["visible"].ToString() == "True")
                        {
                            this.Label1.Text = this.Label1.Text + "<td width='10%'><a href='navigator.aspx?action=yess&amp;cid=" + row["classid"].ToString() + "'><img src='../images/yes.gif' border='0' /></a></td>";
                        }
                        else
                        {
                            this.Label1.Text = this.Label1.Text + "<td width='10%'><a href='navigator.aspx?action=noo&amp;cid=" + row["classid"].ToString() + "'><img src='../images/no.gif' border='0' /></a></td>";
                        }
                        string str5 = this.Label1.Text;
                        this.Label1.Text = str5 + "<td width=12%><input id='Text1' type='text' name='order_" + row["classid"].ToString() + "' size='3' value='" + row["classorder"].ToString() + "' /></td>";
                        this.Label1.Text = this.Label1.Text + "<td width=12%>" + row["classpcs"].ToString() + "</td>";
                        this.Label1.Text = this.Label1.Text + "<td width=20%><a href='navigator_edit.aspx?cid=" + row["classid"].ToString() + "'>编辑</a>";
                        if (row["system"].ToString() == "False")
                        {
                            this.Label1.Text = this.Label1.Text + "|<a href='navigator.aspx?action=del&amp;cid=" + row["classid"].ToString() + "'>移除</a>";
                        }
                        this.Label1.Text = this.Label1.Text + "</td></tr></table>";
                        this.Label1.Text = this.Label1.Text + "<table  width='100%' border='0' cellpadding='0' cellspacing='0'><tr id='tr_" + row["classid"].ToString() + "' style='display:; '><td>";
                        this.Display(row["classid"].ToString(), "&nbsp;&nbsp;" + space);
                        this.Label1.Text = this.Label1.Text + "</td></tr></table>";
                        continue;
                    }
                    string text = this.Label1.Text;
                    this.Label1.Text = text + "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td width=5%><input id='Checkbox1' type='checkbox' name='chk' value=" + row["classid"].ToString() + " /></td><td align=left height=22 width=30%>" + space + "";
                    string str7 = this.Label1.Text;
                    this.Label1.Text = str7 + "<a href='navigator_edit.aspx?cid=" + row["classid"].ToString() + "&lan=cn'>" + row["classname"].ToString() + "</a>";
                    if (row["visible"].ToString() == "True")
                    {
                        this.Label1.Text = this.Label1.Text + "<td width='10%'><a href='navigator.aspx?action=yess&amp;cid=" + row["classid"].ToString() + "'><img src='../images/yes.gif' border='0' /></a></td>";
                    }
                    else
                    {
                        this.Label1.Text = this.Label1.Text + "<td width='10%'><a href='navigator.aspx?action=noo&amp;cid=" + row["classid"].ToString() + "'><img src='../images/no.gif' border='0' /></a></td>";
                    }
                    string str8 = this.Label1.Text;
                    this.Label1.Text = str8 + "<td width=12%><input id='Text1' type='text' name='order_" + row["classid"].ToString() + "' size='3' value='" + row["classorder"].ToString() + "' /></td>";
                    this.Label1.Text = this.Label1.Text + "<td width=12%>" + row["classpcs"].ToString() + "</td>";
                    this.Label1.Text = this.Label1.Text + "<td width=20%><a href='navigator_edit.aspx?cid=" + row["classid"].ToString() + "'>编辑</a>";
                    if (row["system"].ToString() == "False")
                    {
                        this.Label1.Text = this.Label1.Text + "|<a href='navigator.aspx?action=del&amp;cid=" + row["classid"].ToString() + "'>移除</a>";
                    }
                    this.Label1.Text = this.Label1.Text + "</td></tr></table>";
                }
            }
            if ((base.Request.QueryString["action"] != null) && (base.Request.QueryString["cid"] != null))
            {
                string str3 = "0";
                str3 = str3 + re.returnclass("", base.Request.QueryString["cid"].ToString());
                if (base.Request.QueryString["action"].ToString() == "del")
                {
                    SQLAccess.DoSql("delete From DB_Class Where classid in (" + str3 + ")");
                }
                if (base.Request.QueryString["action"].ToString() == "yes")
                {
                    SQLAccess.DoSql("update  DB_Class set ishead=0 Where classid=" + base.Request.QueryString["cid"].ToString() + "");
                }
                if (base.Request.QueryString["action"].ToString() == "no")
                {
                    SQLAccess.DoSql("update  DB_Class set ishead=1 Where classid=" + base.Request.QueryString["cid"].ToString() + "");
                }
                if (base.Request.QueryString["action"].ToString() == "yess")
                {
                    SQLAccess.DoSql("update  DB_Class set visible=0 Where classid=" + base.Request.QueryString["cid"].ToString() + "");
                }
                if (base.Request.QueryString["action"].ToString() == "noo")
                {
                    SQLAccess.DoSql("update  DB_Class set visible=1 Where classid=" + base.Request.QueryString["cid"].ToString() + "");
                }
                base.Response.Write("<script language=javascript>window.location.href='navigator.aspx';</script>");
                base.Response.End();
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string str = base.Request.Form["chk"];
            if (str.ToString() != "")
            {
                string[] strArray = str.Split(new char[] { ',' });
                for (int i = 0; i <= (strArray.Length - 1); i++)
                {
                    if (strArray[i].ToString() != "0")
                    {
                        string str2 = base.Request.Form["order_" + strArray[i]];
                        SQLAccess.DoSql("update DB_Class set classorder=" + str2 + " Where classid =" + strArray[i] + "");
                    }
                }
                base.Response.Write("<script language=javascript>alert('更新成功!');window.location.href='navigator.aspx';</script>");
                base.Response.End();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
          
            this.ImageButton1.Attributes["onclick"] = "return CheckSelect(chk);";
            if (!base.IsPostBack)
            {
                base.ValidateLoginRule(Gift.Model.ENUM.ERule.SelftConfiurationMenu);
                this.Label1.Text = this.Label1.Text + "<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#E2E7EB'><tr class='title01' bgcolor='#E2E7EB'><td width=5%><input id='Checkbox1' type='checkbox' name='chka' value='0' onClick='SelectCheckBox(chk,this)' /></td><td width=30%>";
                this.Label1.Text = this.Label1.Text + "名称";
                this.Label1.Text = this.Label1.Text + "</td><td width=10%>是否显示</td><td width=12%>排序</td><td  width=12%>位置</td><td width=20%>操作</td></tr></table>";
                this.Display("0", "|--");
            }
        }

      
    }
}